﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class bossAttack : MonoBehaviour
{
    // Start is called before the first frame update
    private Transform target; //玩家的位置信息（利用于AI 寻找玩家并攻击）
    private float angle;
    public float gravity;



    //设置想要的方向

    private Vector2 startPos, basePos, newPos;

    void Start()
    {
        target = GameObject.FindGameObjectWithTag("Player").transform;

        Destroy(gameObject, 3f); // 删除子弹
    }

    // Update is called once per frame
    void Update()
    {

        angle = Mathf.Rad2Deg * Mathf.Atan((transform.position.y - target.position.y) / (transform.position.x - target.position.x));

        //判断角度所在象限，并进行修正。

        if (transform.position.x - target.position.x < 0)
        {
            angle = angle - 90;
        }
        else
        {
            angle = angle + 90;
        }
        //设置物体的自身欧拉角，是物体绕自身坐标系在Z轴，旋转Z度。

        transform.localEulerAngles = new Vector3(0, 0, angle);
        transform.Translate(Vector3.up * gravity * Time.deltaTime, Space.Self);
        //Instantiate(gameObject, transform.position, transform.rotation);


    }



    void OnTriggerEnter2D(Collider2D c)
    {
        if (c.tag == "Wall")
        {

            Destroy(c.gameObject);//删除墙
            //加爆炸动画
            Destroy(gameObject); // 删除子弹
        }

        if (c.tag == "Food")
        {

            Destroy(c.gameObject);//删除墙
            //加爆炸动画
            Destroy(gameObject); // 删除子弹
        }

        if (c.tag == "Soda")
        {

            Destroy(c.gameObject);//删除墙
            //加爆炸动画
            Destroy(gameObject); // 删除子弹
        }

        if (c.tag == "Bomb")
        {

            Destroy(c.gameObject);//删除墙
            //加爆炸动画
            Destroy(gameObject); // 删除子弹
        }

    }
}